class Solution {
public:
    vector<int> robTree(TreeNode* root){
        if(root == NULL) return vector<int>{0,0};
        vector<int> left = robTree(root->left);
        vector<int> right = robTree(root->right);
        
        int val1 = root->val + left[0] + right[0];
        
        int val2 = max(left[0],left[1]) + max(right[0],right[1]);
        
        return {val2,val1};
    }
    
    int rob(TreeNode* root) {
        vector<int> res = robTree(root);
        
        return max(res[0],res[1]);  
    }
};
